import React from 'react';
import Taro from '@tarojs/taro';
import {connect} from 'react-redux';
import {View, Button, Image} from '@tarojs/components';
import {AtModal, AtModalContent} from 'taro-ui';

import * as T from '../../types';
import actions from '../../actions/index';
import {store2Props} from '../../selectors';
import {OSS_PATH_PREFIX} from '../../constant';

type IInfoProps = T.IProps & T.IInfoProps;

import './MessageModal.less';
import 'taro-ui/dist/style/components/modal.scss';

// @ts-ignore
@connect<Partial<IInfoProps>, T.IInfoState>(store2Props, actions)
/**
 * ip选择模态框
 */
export default class ResultModal extends React.Component<Partial<IInfoProps>, T.IInfoState> {
  // 使用state值
  constructor(props) {
    super(props);
    this.state = {
      OPERATES: [
        {
          label: '取消',
          func: 'handleCancel',
          className: 'cancel',
        },
        {
          label: '确定',
          func: 'handleSubmit',
          className: 'submit',
        },
      ],
      atModal: {
        closeOnClickOverlay: false,
      },
    };
  }

  /**
   * 取消
   */
  handleCancel = () => {
    this.props.onCancel();
  };

  /**
   * 确定
   */
  handleSubmit = () => {
    this.props.onSubmit();
  };

  /**
   * 渲染
   * @returns
   */
  render() {
    let {
      main: {item},
      modal: {visible, message, extraMessage},
      actions: {action},
    } = this.props;
    const {OPERATES, atModal} = this.state;

    console.log('messagemodel message', message);
    return (
      <AtModal isOpened={visible} className="messageModal" closeOnClickOverlay={atModal.closeOnClickOverlay}>
        <AtModalContent>
          <View className="modalContent">
            <View className="modalTitle">
              <View className="messageTitle">{message}</View>
              <View className="extraTitle">{extraMessage}</View>
            </View>
            <View className="modalFooter">
              {OPERATES.map((i: any, index: number) => (
                <View key={'operate' + index} className={i.className}>
                  <Button onClick={() => this[i.func](i)} className={i.className + 'Button'}>
                    {i.label}
                  </Button>
                </View>
              ))}
            </View>
          </View>
        </AtModalContent>
      </AtModal>
    );
  }
}
